package com.master.demo.controller.app;

import com.master.common.api.FileInfo;
import com.master.common.api.ResponseInfo;
import com.master.demo.common.util.FileUploadUtils;
import com.master.demo.framework.base.BaseController;
import com.master.demo.framework.config.SystemConfig;
import com.master.demo.sys.pojo.command.SysUserCommand;
import com.master.demo.sys.pojo.vo.AppSysUserVO;
import com.master.demo.sys.service.IStatisticsService;
import com.master.demo.sys.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户接口
 *
 * @author: Yang
 * @date: 2023/8/16
 * @version: 1.0.0
 * Copyright Ⓒ 2022 熊扬软件开发工作室 Limited All rights reserved.
 */
@RestController(value = "appUserController")
@RequestMapping("/app/user")
public class UserController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 根据token获取账号详情
     *
     * @author: Yang
     * @date: 2023/06/26
     * @version: 1.0.0
     */
    @GetMapping()
    public ResponseInfo<AppSysUserVO> getLoginSysUser() {
        return sysUserService.getAppSysUserById(getLoginUser().getId());
    }

    /**
     * 账号信息完善
     *
     * @author: Yang
     * @date: 2023/06/26
     * @version: 1.0.0
     */
    @PutMapping("/info.do")
    public ResponseInfo updateSysUser(@RequestBody SysUserCommand command) {
        command.setId(getLoginUser().getId());
        return sysUserService.updateSysUser(command);
    }

    /**
     * 修改账号头像
     *
     * @author: Yang
     * @date: 2023/2/14
     * @version: 1.0.0
     */
    @PostMapping("/avatar")
    public ResponseInfo<FileInfo> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) {
        String filePath = FileUploadUtils.upload(SystemConfig.uploadPath, file).getFilePath();
        return sysUserService.updateSysUserAvatar(getLoginUser().getId(), filePath);
    }

}
